import sqlite3


class AzurePricingPages:
    # noinspection SpellCheckingInspection
    def __init__(self, category=None, product=None, language="zh-cn"):
        self.__cotegary=category
        if self.__cotegary is None:
            self.__product=None
        else:
            self.__product=product

        self.__language=language

    def get_pages(self):
        conn=sqlite3.connect("Urls")
        c=conn.cursor()
        cursor=c.execute(self.get_command)
        page_list=[]
        for row in cursor:
            fullurl="{0}/{1}/{2}".format(row[1], self.__language, row[3])
            page_list.append((row[0], row[2], fullurl))

        return page_list

    @property
    def get_command(self):
        select_command = "SELECT * FROM Azure WHERE Category = {Category} AND Product = {Product}"
        if self.__cotegary == None:
            select_command=select_command[0:select_command.index("Azure") + 6]
        else:
            select_command=select_command.format(self.__cotegary, self.__product)

        return select_command
